<template>
  <el-dialog
    ref="refDlg"
    :title="config.title"
    :visible.sync="dialogShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :before-close="clearForm"
    width="600px"
    @close="closeDialog"
  >
    <table-box
      ref="refTable"
      table-size="mini"
      :table-config="tableConfig"
      :table-height="300"
      :selected-arry.sync="tableSelected"
      :other-filters="otherFilters"
    />
    <div slot="footer">
      <el-button size="mini" @click="closeDialog">取消</el-button>
      <el-button size="mini" type="primary" @click="submitForm">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'SelectDlg',
  components: { },
  props: {
    visible: {
      type: Boolean,
      default: false,
      required: true
    },
    config: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      tableSelected: [],
      otherFilters: [],
      tableConfig: {
        interfacePath: ``,
        buttonGroupCode: 'default',
        hideFuncBar: true,
        tabIndex: '03',
        pageSize: 10,
        order: 'desc',
        // 表格字段动态配置
        setting: [
          {
            prop: 'code',
            label: '编码',
            minWidth: '140'
          },
          {
            prop: 'name',
            label: '名称',
            minWidth: '140'
          }
        ]
      }
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  created() {
    this.tableConfig.interfacePath = this.config.interfacePath
  },

  methods: {

    closeDialog() {
      this.dialogShow = false
      this.clearForm()
    },
    clearForm(done) {
      this.$refs.refForm && this.$refs.refForm.clearValidate()
      done && done()
    },
    // 提交表单处理
    submitForm() {
      this.$emit('change', this.tableSelected || [])
      this.closeDialog()
    }
  }
}
</script>
<style lang='scss' scoped>
.img-upload-container {
  width: fit-content;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  .icon-msg{
    margin-left: 10px;
    color: #999;
  }
}
</style>
